package com.qiaofang.collectmanage.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.qiaofang.collectmanage.base.configuration.SecretaryManageConfiguration;
import com.qiaofang.collectmanage.dao.EsDAO;
import com.qiaofang.collectmanage.dao.util.ConfigUtils;
import com.qiaofang.collectmanage.stub.bean.*;
import com.qiaofang.collectmanage.stub.constants.PlatFormEnum;
import com.qiaofang.collectmanage.stub.constants.TableConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.qiaofang.common.model.page.PageDTO;
import com.qiaofang.collectmanage.service.CollectQualityService;
import com.qiaofang.collectmanage.dao.CollectQualityDao;
import com.qiaofang.collectmanage.dao.domain.CollectQuality;
import com.qiaofang.collectmanage.service.util.CollectQualityServiceConvert;

/**
* Created by generator on 2018-8-1 20:37:55
*/
@Service("collectQualityService")
public class CollectQualityServiceImpl implements CollectQualityService {


    @Autowired
    private CollectQualityDao qualityDao;

    @Autowired
    private EsDAO esDAO;

    @Override
    public CollectQualityDTO getCollectQualityByUuid(String uuid){
        CollectQuality domain = qualityDao.getCollectQualityByUuid(uuid);
        return   CollectQualityServiceConvert.convertDomain2DTO(domain);
    }
    @Override
    public CollectQualityDTO getCollectQualityByQuality(CollectQualityDTO dto){
        CollectQuality domain = qualityDao.getCollectQualityByQuality(CollectQualityServiceConvert.convertDTO2Domain(dto));
          return CollectQualityServiceConvert.convertDomain2DTO(domain);
    }

    @Override
    public int saveCollectQuality(SaveCollectQualityDTO dto) {
         return qualityDao.saveCollectQuality (CollectQualityServiceConvert.convertSaveDTO2Domain(dto));
    }

    @Override
    public int updateCollectQuality (UpdateCollectQualityDTO dto) {
         return qualityDao.updateCollectQuality( CollectQualityServiceConvert.convertUpdateDTO2Domain(dto));
    }


    @Override
    public int removeCollectQualityByUuid (String uuid) {
      return qualityDao.removeCollectQualityByUuid(uuid);
    }
    @Override
    public List<CollectQualityDTO> listCollectQuality(ListCollectQualityDTO dto){
          return  qualityDao.listCollectQuality(CollectQualityServiceConvert.convertListDTO2Domain(dto)).stream().map(CollectQualityServiceConvert::convertDomain2DTO).collect(Collectors.toList());
    }


    @Override
    public List<CollectQualityDTO> listCollectQualityByUuids(List<String> uuidList){
         return  qualityDao.listCollectQualityByUuids(uuidList).stream().map(CollectQualityServiceConvert::convertDomain2DTO).collect(Collectors.toList());
    }
    @Override
    public Long countCollectQuality(CollectQualityDTO dto){
        return  qualityDao.countCollectQuality(CollectQualityServiceConvert.convertDTO2Domain(dto));
    }
    @Override
    public List<CollectQualityDTO> searchCollectQualityByPermission(SearchCollectQualityDTO dto, PageDTO page){
        List<CollectQuality> list = qualityDao.searchCollectQualityByPermission(dto,page);
        return list!=null?list.stream().map(CollectQualityServiceConvert::convertDomain2DTO).collect(Collectors.toList()):null;
    }
    @Override
    public Long countCollectQualityByPermission(SearchCollectQualityDTO dto){
           return qualityDao.countCollectQualityByPermission(dto);
    }

    @Override
    public int timeStatisticsEntry()  {
            List<ChannelSaleAndRentalDTO> channelSaleAndRentalDTOs = esDAO.queryChannelSaleAndRental(PlatFormEnum.QIAOFANG.getValue(),new String[]{ConfigUtils.getIndexHswhRentalHouse(),ConfigUtils.getIndexHswhSaleHouse()},new String[]{TableConstants.INDEX_TYPE_RENTAL_HOUSE,TableConstants.INDEX_TYPE_SALE_HOUSE});
            List<ChannelSaleAndRentalDTO> channelSaleAndRentalDTOBees = esDAO.queryChannelSaleAndRental(PlatFormEnum.BEE.getValue(),new String[]{SecretaryManageConfiguration.getBeeTable()},new String[]{SecretaryManageConfiguration.getBeeType()});
            channelSaleAndRentalDTOs.addAll(channelSaleAndRentalDTOBees);
            List<CollectQuality> collectQualityList = channelSaleAndRentalDTOs.stream().map(CollectQualityServiceConvert::convertSaleAndRentalDTO2Domain).collect(Collectors.toList());
            return qualityDao.saveCollectQualityBatch(collectQualityList);
    }
}
